package com.lee.boot.starter.config;

import com.lee.boot.starter.service.StarterService;
import com.lee.boot.starter.service.impl.StarterServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(StarterServiceImpl.class)
@EnableConfigurationProperties(PropertiesConfig.class)
public class AutoConfig {

    @Autowired
    private PropertiesConfig property;

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "starter", value = "enabled", havingValue = "true")
    public StarterService getStarter() {
        System.out.println(property.getString());
        return new StarterServiceImpl();
    }
}
